package com.sgcc.pda.greendao.dao.h5;

import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteOpenHelper;

/**
 * @author superFan
 * date: 2019/7/18/018 10:59
 * Copyright (c) 2019 hezhongweiqi.Co.Ltd. All rights reserved.
 * description: 集成自greendao的DatabaseOpenHelper ，可进行加密处理
 * <p>
 * 注意；此处使用的是net.sqlcipher.database.SQLiteDatabase 不是使用的android.database.sqlite中的SQLiteDatabase
 */
public class DBH5OpenHelper extends SQLiteOpenHelper {
    private static final String TAG = "DBH5OpenHelper";

    /**
     * @param context
     * @param dbName  数据库名称
     * @param version 数据库版本号
     */
    public DBH5OpenHelper(Context context, @NonNull String dbName, int version) {
        super(context, dbName, null, version);
        //不可忽略的  进行so库加载
        //不使用系统自带的加密so库，使用path中的
        String fromPath = "/.platform/data/lib/libsqlcipher.so";
        try {
            System.load(fromPath);
        } catch (UnsatisfiedLinkError e) {
            Log.e("load", "log", e);
        } catch (RuntimeException e) {
            Log.e("load", "log", e);
        }
    }


    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d(TAG, "onCreate() returned: 可以创建数据表，有H5应用动态创建表");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "onUpgrade() returned: old=" + oldVersion + "new:" + newVersion);
        if (newVersion > oldVersion) {


        }
    }

}
